/*
 * Copyright 2025 The Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *@file    : feature.h
 *@brief   : feature
 *@authors : zhanglei, zhanglei_723@126.com
 *@version : v1.0
 *@data    : 2025/8/30
 *
 */

#ifndef FEATURE_H
#define FEATURE_H

#include "common/type.h"
#include "common/make_unique.hpp"

namespace feature {

struct FeaturePoint {
    Vector2d image_point;
    Vector128d descriptor;
    Vector2d undistorted_point;
    Vector3d normalized_point;
    // confidence of this keypoint
    double score;
    Vector256d global_feature;
};

/**
 * @brief Sparse feature class used to collect measurements
 *
 * This feature class allows for holding of all tracking information for a given feature.
 * Each feature has a unique ID assigned to it, and should have a set of feature tracks alongside it.
 * See the FeatureDatabase class for details on how we load information into this, and how we delete features.
 */
class Feature {
public:
  Feature();
  Feature(const uint8_t& camera_id, const uint64_t& frame_id, const uint64_t& feature_id, const FeaturePoint& feature);
  std::unique_ptr<Vector3d> GetNormalizedPointFromCameraIdAndIndex(const uint8_t& camera_id, const uint32_t& point_idx);
  std::vector<FeaturePoint> GetFeaturePointFromCameraId(const uint8_t& camera_id);
  std::vector<uint64_t> GetFrameIdsFromCameraId(const uint8_t& camera_id);
  /// Unique ID of this feature
  uint64_t feature_id_;
  // frame id and feature
  std::unordered_map<uint8_t, std::vector<FeaturePoint>> map_camera_id_and_feature_;
  std::unordered_map<uint8_t, std::vector<uint64_t>> map_camera_and_frame_id_;

  Vector3d world_point_ = Vector3d(0,0,0);
};

} // namespace feature

#endif /* FEATURE_H */